Following my original posting, I did a bit of hunitng in the source and
used them to come up with these functions:
/* get_x.c
a function to return the x coord of a point */
#include "postgres.h"
#include "utils/geo_decls.h"
double
get_x(Point *pt)
{
if (!PointerIsValid(pt))
return NULL;
return pt->x;
} /* get_x() */
/* get_y.c
a function to return the y coord of a point */
#include "postgres.h"
#include "utils/geo_decls.h"
double
get_y(Point *pt)
{
if (!PointerIsValid(pt))
return NULL;
return pt->y;
} /* get_y() */
... then I do ...
cc -c get_<x|y>.c -I/usr/local/pgsql/include
ld -G -Bdynamic -o get_<x|y>.so get_<x|y>.o
which gives me get_x.so and get_y.so
... then I do (within psql)...
brecard10=> CREATE FUNCTION get_<x|y>(point) RETURNS float
brecard10-> AS '/usr/people/postgres/get_<x|y>.so' LANGUAGE 'c';
AND NOW FOR THE CRAZY PART...
brecard10=> select * from points;
id|pos
--+-----------
1|(1,2)
2|(-1.3,4.77)
3|(0,-3)
(3 rows)
brecard10=> select id,pos,get_x(pos) from points;
id|pos |get_x
--+-----------+-----
1|(1,2) | 1
2|(-1.3,4.77)| -1.3
3|(0,-3) | 0
(3 rows)
Rejoice I thought, I'm a genius, wealth, power and good looks will soon
follow...
brecard10=> select id,pos,get_y(pos) from points;
id|pos |get_y
--+-----------+-----
1|(1,2) | 1
2|(-1.3,4.77)| -1.3
3|(0,-3) | 0
(3 rows)
There goes the nobel, my seat in the parliament and my winning smile!
I have no training in C so I've reached this far by trial and error. I
have however discovered that if write a function such as
/* pants.c
weird of what! */
#include "postgres.h"
#include "utils/geo_decls.h"
double
pants(Point *pt)
{
return 2.0;
}
and compile it as above and make it a function I get:
brecard10=> select id,pos,pants(pos) from points;
id|pos |pants
--+-----------+-----
1|(1,2) | 1
2|(-1.3,4.77)| -1.3
3|(0,-3) | 0
(3 rows)
HELP!
WHAT'S GOING ON!!!
Why can't I get to pt->y?
Why does function pants behave just like get_x (and get_y)?
Stuart.
+-------------------------+--------------------------------------+
| Stuart Rison | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street |
| Tel. (0171) 878 4041 | London, W1P 8BT, UNITED KINGDOM. |
| Fax. (0171) 878 4040 | stuart@ludwig.ucl.ac.uk |
+-------------------------+--------------------------------------+